package com.vitamo.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.cellview.client.CellBrowser;
import com.google.gwt.view.client.TreeViewModel;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionModel.AbstractSelectionModel;
import com.google.gwt.view.client.NoSelectionModel;
import com.google.gwt.view.client.TreeViewModel.NodeInfo;
import com.google.gwt.view.client.TreeViewModel.DefaultNodeInfo;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.SimpleCheckBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.sun.java.swing.plaf.windows.resources.windows;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;

public class FormulaireInscription extends DialogBox{

	private GreetingServiceAsync greetingService;
	private Label LabelVerification;
	private TextBox username,nom,prenom,email,nump,numt,numf;
	private ListBox type;
	private TextArea Adress;
	private PasswordTextBox pwd,pwdV;
	public FormulaireInscription(GreetingServiceAsync s) {
		super();
		this.greetingService=s;
		PopupPanel main=new PopupPanel();
		AbsolutePanel P = new AbsolutePanel();
		//setWidget(absolutePanel);
		main.add(P);
		this.add(main);
		this.setSize("518px", "506px");
		main.setSize("518px", "506px");
			P.setSize("424px", "480px");
			
			Label lblCrerVotreCompte = new Label("Cr\u00E9ez votre compte VITAMO");
			lblCrerVotreCompte.setStyleName("LabelGras");
			P.add(lblCrerVotreCompte, 58, 0);
			
			Label lblNewLabel = new Label("Nom d'utilisateur :");
			P.add(lblNewLabel, 65, 52);
			
			Label lblNewLabel_1 = new Label("Cr\u00E9ez un mot de passe :");
			P.add(lblNewLabel_1, 27, 113);
			
			Label lblNewLabel_2 = new Label("Nom :");
			P.add(lblNewLabel_2, 135, 177);
			
			Label lblNewLabel_3 = new Label("Pr\u00E9nom :");
			P.add(lblNewLabel_3, 117, 206);
			
			Label lblNewLabel_4 = new Label("Adresse :");
			P.add(lblNewLabel_4, 117, 235);
			
			Label lblNewLabel_5 = new Label("Adresse de messagerie :");
			P.add(lblNewLabel_5, 24, 331);
			
			Label lblNumroDeFixe = new Label("Num\u00E9ro de Fixe :");
			P.add(lblNumroDeFixe, 69, 360);
			
			LabelVerification = new Label("");
			LabelVerification.setStyleName("valider");
			P.add(LabelVerification, 10, 24);
			LabelVerification.setSize("404px", "28px");
			
			Label lblNewLabel_6 = new Label("Num\u00E9ro de Fax :");
			P.add(lblNewLabel_6, 72, 384);
			
			Label lblNewLabel_7 = new Label("Num\u00E9ro de mobile :");
			P.add(lblNewLabel_7, 56, 415);
			
			Label lblRle = new Label("R\u00F4le :");
			P.add(lblRle, 135, 82);
			
			Label lblNewLabel_8 = new Label("Retapez le mot de passe :");
			P.add(lblNewLabel_8, 17, 146);
			
			 username = new TextBox();
			 username.addValueChangeHandler(new ValueChangeHandler<String>() {
			 	public void onValueChange(ValueChangeEvent<String> event) {
			 	greetingService.Verifier(username.getText(), new AsyncCallback<String>() {
					
					@Override
					public void onSuccess(String result) {
						// TODO Auto-generated method stub
						LabelVerification.setText(result);
					}
					
					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub
						
						Window.alert("Erreur de connexion");	
					}
				});
			 	}
			 });
			P.add(username, 176, 52);
			username.setSize("214px", "11px");
			
		 type = new ListBox();
			type.addItem("Client");
			type.addItem("Fournisseur");
			type.addItem("Administrateur");
			type.addItem("Responsable");
			P.add(type, 176, 81);
			type.setSize("224px", "22px");

			 pwd = new PasswordTextBox();
			P.add(pwd, 176, 113);
			pwd.setSize("214px", "11px");

		 pwdV = new PasswordTextBox();
			P.add(pwdV, 176, 141);
			pwdV.setSize("214px", "11px");

			 nom = new TextBox();
			P.add(nom, 176, 177);
			nom.setSize("214px", "11px");
			
			 prenom = new TextBox();
			P.add(prenom, 176, 206);
			prenom.setSize("214px", "11px");
			
		    Adress = new TextArea();
			P.add(Adress, 176, 235);
			Adress.setSize("214px", "71px");

		    email = new TextBox();
			P.add(email, 176, 326);
			email.setSize("214px", "11px");
			
		    numt = new TextBox();
			P.add(numt, 176, 355);
			numt.setSize("214px", "11px");
			
			numf = new TextBox();
			P.add(numf, 176, 384);
			numf.setSize("214px", "11px");
			
			nump = new TextBox();
			P.add(nump, 176, 413);
			nump.setSize("214px", "11px");
			
			Button btnAnnuler = new Button("Annuler");
			btnAnnuler.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
				 hide();
				}
			});
			P.add(btnAnnuler, 340, 442);
			
			Button btnValider = new Button("Valider");
			btnValider.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
					
					greetingService.CreerUtilisateur(username.getText(),pwd.getText(), type.getItemText(type.getSelectedIndex()), nom.getText(), prenom.getText(), Adress.getText(), email.getText(), numt.getText(), numf.getText(), nump.getText(),new AsyncCallback<String>() {
						
						@Override
						public void onSuccess(String result) {
							// TODO Auto-generated method stub
							Window.alert(result);
						}
						
						@Override
						public void onFailure(Throwable caught) {
							// TODO Auto-generated method stub
						Window.alert("Erreur de connexion");	
						}
					});
				}
			});
			P.add(btnValider, 278, 442);
			
	}
}
